﻿using FineAdmin.Common;
using FineAdmin.IService;
using FineAdmin.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace HuiJi.CMS.Blog.Controllers
{

    public class FriendlyController : BaseController
    {
        // GET: Friendly
        public IFriendlyService FriendlyService { get; set; }
        public ActionResult Index()
        {

            ViewBag.Active = "Friendly";
            ViewBag.FriendlyList= FriendlyService.GetAll();
            return View();
        }

        public ActionResult Add(FriendlyModel model, string captcha)
        {
            if (Session["session_verifycode_type4"].IsEmpty() || Md5.md5(captcha.ToLower(), 16) != Session["session_verifycode_type4"].ToString())
            {
                return Json(SuccessTip("申请失败，验证码不正确"), JsonRequestBehavior.DenyGet);
            }
            model.State = 2;
            model.CreateTime = DateTime.Now;
            model.UpdateTime = DateTime.Now;
            model.UpdateUserId = 1;
            model.CreateUserId = 1;
            FriendlyService.Insert(model);

            return Json(SuccessTip("申请成功，审核后将会展示"), JsonRequestBehavior.DenyGet);
        }

        public ActionResult GetSubmitCode()
        {
            return File(new VerifyCode().GetVerifyCode(type: 4), @"image/Gif");
        }
    }
}